package router

import (
	"3-6zk/client/client"
	"3-6zk/client/enit"
	"3-6zk/common/proto/user"
	"github.com/gin-gonic/gin"
	"net/http"
)

func Login(c *gin.Context) {
	var data enit.Login
	err := c.ShouldBind(&data)
	if err != nil {
		c.JSON(http.StatusInternalServerError, &gin.H{
			"code": 500,
			"Data": err.Error(),
		})
		return
	}
	login, err := client.Login(c, &user.LoginReq{
		Phone:    data.Phone,
		Password: data.Password,
		SendSms:  data.SendSms,
	})
	if err != nil {
		c.JSON(http.StatusInternalServerError, &gin.H{
			"code": 500,
			"Data": err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, &gin.H{
		"code": 200,
		"data": login,
	})
}
func SendSms(c *gin.Context) {
	var data enit.SendSms
	err := c.ShouldBind(&data)
	if err != nil {
		c.JSON(http.StatusInternalServerError, &gin.H{
			"code": 500,
			"Data": err.Error(),
		})
		return
	}
	sms, err := client.SendSms(c, &user.SendSmsReq{
		Phone:  data.Phone,
		Soures: data.Soures,
	})
	if err != nil {
		c.JSON(http.StatusInternalServerError, &gin.H{
			"code": 500,
			"Data": err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, &gin.H{
		"code": 200,
		"data": sms,
	})
}
